package com.jsh.erp.service.retailRecord;

import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.IdUtils;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Service(value = "retailRecord_component")
@RetailRecordResource
public class RetailRecordComponent implements ICommonQuery {

    @Resource
    private RetailRecordService retailRecordService;

    @Override
    public Object selectOne(String id) throws Exception {
        return retailRecordService.getRetailRecord(id);
    }

    @Override
    public List<?> select(Map<String, String> map)throws Exception {
        return getRetailRecordList(map);
    }

    private List<?> getRetailRecordList(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        String order = QueryUtils.order(map);
        String filter = QueryUtils.filter(map);
        return retailRecordService.select(QueryUtils.offset(map), QueryUtils.rows(map));
    }

    @Override
    public Long counts(Map<String, String> map) throws Exception{
        String search = map.get(Constants.SEARCH);
        return retailRecordService.countRetailRecord();
    }

       @Override
    public int insert(JSONObject obj, HttpServletRequest request) throws Exception{
        obj.put("id", IdUtils.getUUID());
        return retailRecordService.insertRetailRecord(obj, request);
    }

    @Override
    public int update(JSONObject obj, HttpServletRequest request)throws Exception {
        return retailRecordService.updateRetailRecord(obj, request);
    }

    @Override
    public int delete(String id, HttpServletRequest request)throws Exception {
        return retailRecordService.deleteRetailRecord(id, request);
    }

    @Override
    public int deleteBatch(String ids, HttpServletRequest request)throws Exception {
        return retailRecordService.batchDeleteRetailRecord(ids, request);
    }

    @Override
     public int checkIsNameExist(String id, String name) throws Exception{
        return retailRecordService.checkIsNameExist(id, name);
    }

}
